package com.loubobooo.personal.blog.service.impl;

import com.loubobooo.personal.blog.entity.Menu;
import com.loubobooo.personal.blog.entity.vo.MenuVO;
import com.loubobooo.personal.blog.mapper.MenuMapper;
import com.loubobooo.personal.blog.mapper.custom.MenuMapperCustom;
import com.loubobooo.personal.blog.service.MenuService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service public class MenuServiceImpl implements MenuService {

    @Autowired private MenuMapperCustom menuMapperCustom;

    @Autowired private MenuMapper menuMapper;

    @Override public List<MenuVO> listMenu(Integer status) {
        return menuMapperCustom.listMenu(status);
    }

    @Override public void insertMenu(Menu menu) {
        menuMapper.insertSelective(menu);
    }

    @Override public void deleteMenu(Integer id) {
        menuMapper.deleteByPrimaryKey(id);
    }

    @Override public void updateMenu(Menu menu) {
        menuMapper.updateByPrimaryKeySelective(menu);
    }

    @Override public MenuVO getMenuById(Integer id) {
        MenuVO menuVO = new MenuVO();
        Menu menu = menuMapper.selectByPrimaryKey(id);
        BeanUtils.copyProperties(menu, menuVO);
        return menuVO;
    }
}
